﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IMIS_ERP.Web.Order_Info
{
    public partial class Search_Manager_Factory_Area : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["UCode"].ToString().Substring(12, 1) == "0")
                {
                    Response.Write("<script>alert('没有权限！');location.href='../ERP_Manager/EM_Page_Main.aspx';</script>");
                }
                Bind_PID();
            }
        }

        /// <summary>绑定加工中心ID
        ///     <remarks>2011-03-14 河大信管团队</remarks>
        /// </summary>
        private void Bind_PID()
        {
            string fiProvince = "", fiCity = "";
            if (Session["UType1"].ToString() == "0")
            {
                fiProvince = "%%";
                fiCity = " like '%%'";
            }
            else if (Session["UType1"].ToString() == "1")
            {
                fiProvince = Session["UProvince"].ToString();
                fiCity = " like '%%'";
            }
            else if (Session["UType1"].ToString() == "2")
            {
                fiProvince = Session["UProvince"].ToString();
                fiCity = "='" + Session["UCity"].ToString() + "'";
            }
            IMIS_ERP.BLL.Factory_Info bll = new BLL.Factory_Info();
            SqlDataReader dr = bll.GetfiID_M(fiProvince, fiCity);
            ddlFID.DataSource = dr;
            ddlFID.DataTextField = "fiID";
            ddlFID.DataBind();
            dr.Close();
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            IMIS_ERP.BLL.Order_Info bll = new IMIS_ERP.BLL.Order_Info();
            DataSet ds = bll.GetfiSum_Area(ddlFID.SelectedValue,txthTime1.Text.Trim() + " 00:00:00", txthTime2.Text.Trim() + " 23:59:59");
            //用于GridView
            DataTable dt = new DataTable();
            dt.Columns.Add("oiFiID");
            dt.Columns.Add("TaskSum");
            dt.Columns.Add("DoneSum");
            dt.Columns.Add("HandSum");
            dt.Columns.Add("InstallSum");
            //用于Chart
            DataTable dt1 = new DataTable();
            dt1.Columns.Add("oiType");
            dt1.Columns.Add("oiSum");

            if (ds.Tables[0].Rows.Count > 0)
            {
                dt.Rows.Add(ddlFID.SelectedValue, ds.Tables[0].Rows[0]["oiSum"].ToString(), ds.Tables[1].Rows.Count > 0 ? ds.Tables[1].Rows[0]["oiSum"].ToString() : "0", ds.Tables[2].Rows.Count > 0 ? ds.Tables[2].Rows[0]["oiSum"].ToString() : "0", ds.Tables[3].Rows.Count > 0 ? ds.Tables[3].Rows[0]["oiSum"].ToString() : "0");
                dt1.Rows.Add("待产", ds.Tables[0].Rows[0]["oiSum"].ToString());
                dt1.Rows.Add("完成", ds.Tables[1].Rows.Count > 0 ? ds.Tables[1].Rows[0]["oiSum"].ToString() : "0");
                dt1.Rows.Add("交付", ds.Tables[2].Rows.Count > 0 ? ds.Tables[2].Rows[0]["oiSum"].ToString() : "0");
                dt1.Rows.Add("已安装", ds.Tables[3].Rows.Count > 0 ? ds.Tables[3].Rows[0]["oiSum"].ToString() : "0");
            }
            else
            {
                dt.Rows.Add(ddlFID.SelectedValue, "0", "0", "0", "0");
                dt1.Rows.Add("待产", "0");
                dt1.Rows.Add("完成", "0");
                dt1.Rows.Add("交付", "0");
                dt1.Rows.Add("已安装", "0");
            }
            GV.DataSource = dt;
            GV.DataBind();

            //设置图表的数据源
            Chart1.DataSource = dt1;

            //设置图表Y轴对应项
            Chart1.Series[0].YValueMembers = "oiSum";

            //设置图表X轴对应项
            Chart1.Series[0].XValueMember = "oiType";

            //绑定数据
            Chart1.DataBind();
        }

        /// <summary>响应GridView事件：创建数据行时
        /// 	<remark>2010-12-08 BY 河北大学信管团队</remark>
        /// </summary>
        protected void GV_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //为数据行增加鼠标移动到行特性
                e.Row.Attributes.Add("onmouseover", "c=style.backgroundColor;this.style.backgroundColor='" + IMIS_ERP.BLL.Assistant.getColor1 + "'");
                //为数据行增加鼠标离开行特性
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
            }
        }
    }
}